import java.util.Stack;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * user:likai
 * Date:2022-11-15
 * Time:10:53
 */
class Solution {
    public int evalRPN(String[] tokens) {
        Stack<Integer> stack=new Stack<>();
        for (String x:tokens) {
            if(x.equals("*")||x.equals("/")||x.equals("+")||x.equals("-")){
                int num2=stack.pop();
                int num1=stack.pop();
                switch (x){
                    case "*":
                        stack.push(num1*num2);
                        break;

                    case "/":
                        stack.push(num1/num2);
                        break;

                    case "+":
                        stack.push(num1+num2);
                        break;
                    case "-":
                        stack.push(num1-num2);
                        break;
                }
            }else{
                stack.push(Integer.parseInt(x));
            }
        }
        return stack.pop();
    }

    public boolean isValid(String s) {

        Stack stack=new Stack<Character>();
        for(int i=0;i<s.length();i++){
            char a=s.charAt(i);
            if((a=='(')||(a=='{')||(a=='[')){
                stack.push(a);
            }else{
                if(stack.empty()){
                    return false;
                }
                if(a==')'&&stack.peek().equals('(')){
                    stack.pop();
                }else if(a=='}'&&stack.peek().equals('{')){
                    stack.pop();
                }else if(a==']'&&stack.peek().equals('[')){
                    stack.pop();
                }else{
                    return false;
                }
            }
        }
        if(stack.empty()){
            return true;
        }
        return false;
    }
    public boolean IsPopOrder(int [] pushA,int [] popA) {
        Stack<Integer> stack=new Stack<>();
        int j=0;
        for (int i = 0; i < pushA.length; i++) {
            stack.push(pushA[i]);
            while(!stack.empty()&&stack.peek().equals(popA[j])){
                stack.pop();
                j++;
            }
        }
        if(j==popA.length&&stack.empty()){
            return true;
        }else {
            return false;
        }
    }
}
public class MinStack {

        public Stack<Integer> stack1;
        public Stack<Integer> stack2;
        public MinStack() {
            stack1=new Stack<>();
            stack2=new Stack<>();
        }
        public void push(int val) {
            if(stack1.empty()){
                stack1.push(val);
                stack2.push(val);
                return;
            }
            stack1.push(val);
            if(stack1.peek()<=stack2.peek()){
                stack2.push(val);
            }
            return;
        }

        public void pop() {
            if(stack1.peek().equals(stack2.peek())){
                stack1.pop();
                stack2.pop();
            }else{
                stack1.pop();
            }
            return;
        }

        public int top() {
            return stack1.peek();
        }

        public int getMin() {
            return stack2.peek();
        }
}
